<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>分销商管理系统</title>
    <link rel="stylesheet" type="text/css" href="__STATIC__/Dealer/css/login.css"  />
</head>
<body>
<div id="content">
    <form method="post">
        <input type="hidden" name="ajax" value="ajax"/>
        <dl>
            <dt>分销商--管理系统</dt>
            <dd><input type="text" name="username" placeholder="请输入用户名" class="utext" maxlength="12" /></dd>
            <dd><input type="password" name="password" placeholder="请输入登录密码" class="ptext" maxlength="18" /></dd>
            <dd><input type="text" name="code" placeholder="请输入验证码" class="code" maxlength="5" />
                <img src="{:U('Login/showCode')}" border="0" id="verify" style="width:160px;"/></dd>
            <dd><input type="submit" name="login" value="登 录" class="button" /></dd>
        </dl>
    </form>
</div>
<script type="text/javascript" src="__PUBLIC__/js/jquery1.11.1.min.js"></script>
<script type="text/javascript" src="__STATIC__/layer/layer.js"></script>
<script>
    $(function() {
        $('#content input').eq(0).focus();
        $('body input:text, input:password, textarea').focus(function() {
            $(this).css({'border':'solid 1px #398700','boxShadow':'0px 0px 8px #398700'});
        });
        $('body input:text, input:password, textarea').blur(function() {
            $(this).css({'border':'solid 1px #ccc','boxShadow':'none'});
        });


        $('.button').click(function(event) {
                event.preventDefault();
                var username=$('#content .utext').val();
                var password=$('#content .ptext').val();
                var code=$('#content .code').val();
                if (!/^[a-zA-Z0-9_-]|[\u4e00-\u9fa5]{2,16}$/.test(username)) {
                    layer.msg('请输入正确的用户名');
                    $('#content .utext').focus();
                    return;
                }
                if (password.length<6) {
                    layer.msg('请输入6位数以上的密码');
                    $('#content .ptext').focus();
                    return;
                }
                // if (!/^[a-zA-Z0-9]{5}$/.test(code)) {
                //     layer.msg('请输入正确的验证码');
                //     $('#content .code').focus();
                //     return;
                // }
                $.ajax({
                    url:'{:U("Login/login")}',
                    dataType:"json",
                    type:'POST',
                    cache:false,
                    data:{username:username,password:password,code:code},
                    success: function(data) {
                    if (data.status==1) {
                        layer.msg('登录成功');
                        location.href="/Reseller/Index/index";
                    }else {
                        $('#verify').click();
                        layer.msg(data.msg);
                    }
                }
            });
        });

        //更换验证码
        function rcode(obj,img_src){
            if(img_src.indexOf('?') > -1){
                obj.attr('src',img_src+'&mt='+Math.random());
            }else{
                obj.attr('src',img_src+'?mt='+Math.random());
            }
        }

        $('#verify').click(function() {
            var num=Math.random();
            $(this).attr('src',"{:U('Login/showCode','',false)}/num="+num);
        });
    });
</script>
</body>
</html>
